<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>

<div id="content">
<?php echo $content_top; ?>
<div class="breadcrumb">
  <?php foreach ($breadcrumbs as $breadcrumb) { ?>
  <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
  <?php } ?>
</div>
<!-- 产品 -->
<div class="page-header">
  <h1><?php echo $heading_title; ?></h1>
</div>
<div class="product-info row">
  <?php if ($thumb || $images) { ?>
  <div class="span8">
    <?php if ($thumb) { ?>
    <div class="image"><a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>" class="colorbox" rel="colorbox"><img src="<?php echo $thumb; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" id="image" /></a></div>
    <?php } ?>
    <?php if ($images) { ?>
    <div class="image-additional">
      <?php foreach ($images as $image) { ?>
      <a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="colorbox" rel="colorbox"><img src="<?php echo $image['thumb']; ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" /></a>
      <?php } ?>
    </div>
    <?php } ?>
  </div>
  <?php } ?>
  <div class="span4">
    <div class="description">
      <?php if ($manufacturer) { ?>
      <span><?php echo $text_manufacturer; ?></span> <a href="<?php echo $manufacturers; ?>"><?php echo $manufacturer; ?></a><br />
      <?php } ?>
      <span><?php echo $text_model; ?></span> <?php echo $model; ?><br />
      <?php if ($reward) { ?>
      <span><?php echo $text_reward; ?></span> <?php echo $reward; ?><br />
      <?php } ?>
      <span><?php echo $text_stock; ?></span> <?php echo $stock; ?></div>
    <?php if ($price) { ?>
    <div class="price"><?php echo $text_price; ?>
      <?php if (!$special) { ?>
      <?php echo $price; ?>
      <?php } else { ?>
      <span class="price-old"><?php echo $price; ?></span> <span class="price-new"><?php echo $special; ?></span>
      <?php } ?>
      <br />
      <?php if ($tax) { ?>
      <span class="price-tax"><?php echo $text_tax; ?> <?php echo $tax; ?></span><br />
      <?php } ?>
      <?php if ($points) { ?>
      <span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span><br />
      <?php } ?>
      <?php if ($discounts) { ?>
      <br />
      <div class="discount">
        <?php foreach ($discounts as $discount) { ?>
        <?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
        <?php } ?>
      </div>
      <?php } ?>
    </div>
    <?php } ?>
    <?php if ($options) { ?>
    <div class="options">
      <form class="form-horizontal">
        <legend><?php echo $text_option; ?></legend>
        <?php foreach ($options as $option) { ?>
        <?php if ($option['type'] == 'select') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label" for="option[<?php echo $option['product_option_id']; ?>]">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?> </label>
            <select class="span2" name="option[<?php echo $option['product_option_id']; ?>]">
              <option value=""><?php echo $text_select; ?></option>
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
              <?php if ($option_value['price']) { ?>
              （<?php echo $option_value['price_prefix']; ?> <?php echo $option_value['price']; ?>）
              <?php } ?>
              </option>
              <?php } ?>
            </select>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'radio') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <?php foreach ($option['option_value'] as $option_value) { ?>
            <div class="controls">
              <label class="radio" for="option-value-<?php echo $option_value['product_option_value_id']; ?>">
                <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
                <?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                （<?php echo $option_value['price_prefix']; ?> <?php echo $option_value['price']; ?>）
                <?php } ?>
              </label>
            </div>
            <?php } ?>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'checkbox') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <?php foreach ($option['option_value'] as $option_value) { ?>
            <div class="controls">
              <label class="checkbox" for="option-value-<?php echo $option_value['product_option_value_id']; ?>">
                <input type="checkbox" name="option[<?php echo $option['product_option_id']; ?>][]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" />
                <?php echo $option_value['name']; ?>
                <?php if ($option_value['price']) { ?>
                （<?php echo $option_value['price_prefix']; ?> <?php echo $option_value['price']; ?>）
                <?php } ?>
              </label>
            </div>
            <?php } ?>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'image') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <?php if ($option['required']) { ?>
            <span class="required">*</span>
            <?php } ?>
            <?php echo $option['name']; ?>
            <table class="option-image">
              <?php foreach ($option['option_value'] as $option_value) { ?>
              <tr>
                <td style="width: 1px;"><input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" /></td>
                <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><img src="<?php echo $option_value['image']; ?>" alt="<?php echo $option_value['name'] . ($option_value['price'] ? ' ' . $option_value['price_prefix'] . $option_value['price'] : ''); ?>" /></label></td>
                <td><label for="option-value-<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
                    <?php if ($option_value['price']) { ?>
                    （<?php echo $option_value['price_prefix']; ?> <?php echo $option_value['price']; ?>）
                    <?php } ?>
                  </label></td>
              </tr>
              <?php } ?>
            </table>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'text') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls">
              <input type="text" class="input-medium" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" />
            </div>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'textarea') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls">
              <textarea class="input-medium" name="option[<?php echo $option['product_option_id']; ?>]" cols="40" rows="5"><?php echo $option['option_value']; ?></textarea>
            </div>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'file') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls"> <a id="button-option-<?php echo $option['product_option_id']; ?>" class="btn"><?php echo $button_upload; ?></a>
              <input type="hidden" name="option[<?php echo $option['product_option_id']; ?>]" value="" />
            </div>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'date') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls">
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="date span2" />
            </div>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'datetime') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls">
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="datetime span2" />
            </div>
          </div>
        </div>
        <?php } ?>
        <?php if ($option['type'] == 'time') { ?>
        <div class="control-group">
          <div id="option-<?php echo $option['product_option_id']; ?>" class="option">
            <label class="control-label">
              <?php if ($option['required']) { ?>
              <span class="required">*</span>
              <?php } ?>
              <?php echo $option['name']; ?></label>
            <div class="controls">
              <input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['option_value']; ?>" class="time span2" />
            </div>
          </div>
        </div>
        <?php } ?>
        <?php } ?>
      </form>
    </div>
    <?php } ?>
    <div class="cart">
      <div><?php echo $text_qty; ?>
        <input class="span1" type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
        <input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
        &nbsp;
        <input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="btn btn-success btn-large" />
        <?php if ($minimum > 1) { ?>
        <div class="minimum"><?php echo $text_minimum; ?></div>
        <?php } ?>
      </div>
    </div>
    <?php if ($review_status) { ?>
    <div class="review"> <img src="catalog/view/theme/ninghao/image/stars-<?php echo $rating; ?>.png" alt="<?php echo $reviews; ?>" /> </div>
    <?php } ?>
    <div class="action-btn"> <a class="btn" onclick="addToWishList('<?php echo $product_id; ?>');"><?php echo $button_wishlist; ?></a> <a class="btn" onclick="addToCompare('<?php echo $product_id; ?>');"><?php echo $button_compare; ?></a>
      <?php if ($review_status) { ?>
      <a class="btn" onclick="$('a[href=\'#tab-review\']').trigger('click');"><i class="icon-comment"></i> <?php echo $text_write; ?> <?php echo $reviews; ?></a>
      <?php } ?>
    </div>
  </div>
  
 </div>
 
 <div id="product-tab">
  <ul id="tab" class="nav nav-tabs">
    <li class="active"><a href="#tab-description" data-toggle="tab"><?php echo $tab_description; ?></a></li>
    <?php if ($attribute_groups) { ?>
    <li><a href="#tab-attribute" data-toggle="tab"><?php echo $tab_attribute; ?></a></li>
    <?php } ?>
    <?php if ($review_status) { ?>
    <li><a href="#tab-review" data-toggle="tab"><?php echo $tab_review; ?></a></li>
    <?php } ?>
    <?php if ($products) { ?>
    <li><a href="#tab-related" data-toggle="tab"><?php echo $tab_related; ?> <span class="badge badge-info"><?php echo count($products); ?></span></a></li>
    <?php } ?>
  </ul>
  <div id="myTabContent" class="tab-content">
    <div id="tab-description" class="tab-pane fade in active"><?php echo $description; ?></div>
    <?php if ($attribute_groups) { ?>
    <div id="tab-attribute" class="tab-pane fade">
      <table class="attribute">
        <?php foreach ($attribute_groups as $attribute_group) { ?>
        <thead>
          <tr>
            <td colspan="2"><?php echo $attribute_group['name']; ?></td>
          </tr>
        </thead>
        <tbody>
          <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
          <tr>
            <td><?php echo $attribute['name']; ?></td>
            <td><?php echo $attribute['text']; ?></td>
          </tr>
          <?php } ?>
        </tbody>
        <?php } ?>
      </table>
    </div>
    <?php } ?>
    <?php if ($review_status) { ?>
    <div id="tab-review" class="tab-pane fade">
      <div id="review"></div>
      <legend id="review-title"><?php echo $text_write; ?></legend>
      <form class="form-horizontal">
        <div class="control-group">
          <label class="control-label" for="name"><?php echo $entry_name; ?></label>
          <div class="controls">
            <input type="text" name="name" value="" />
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="text"><?php echo $entry_review; ?></label>
          <div class="controls">
            <textarea name="text" cols="40" rows="8" style="width: 98%;"></textarea>
            <p class="help-block"><?php echo $text_note; ?></p>
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="rating"><?php echo $entry_rating; ?></label>
          <div class="controls">
            <input type="radio" name="rating" value="1" />
            &nbsp;
            <input type="radio" name="rating" value="2" />
            &nbsp;
            <input type="radio" name="rating" value="3" />
            &nbsp;
            <input type="radio" name="rating" value="4" />
            &nbsp;
            <input type="radio" name="rating" value="5" />
            <?php echo $entry_bad; ?> -> <?php echo $entry_good; ?><br />
          </div>
        </div>
        <div class="control-group">
          <label class="control-label" for="captcha"><?php echo $entry_captcha; ?></label>
          <div class="controls">
            <input type="text" name="captcha" value="" />
            <p class="help-block"><img src="index.php?route=product/product/captcha" alt="" id="captcha" /></p>
          </div>
        </div>
        <div class="form-actions row"> <a id="button-review" class="btn btn-large span1 btn-primary"><?php echo $button_continue; ?></a> </div>
      </form>
    </div>
    <?php } ?>
    <?php if ($products) { ?>
    <div id="tab-related" class="tab-pane fade">
      <div class="box-product">
        <?php foreach ($products as $product) { ?>
        <div>
          <?php if ($product['thumb']) { ?>
          <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
          <?php } ?>
          <div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
          <?php if ($product['price']) { ?>
          <div class="price">
            <?php if (!$product['special']) { ?>
            <?php echo $product['price']; ?>
            <?php } else { ?>
            <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
            <?php } ?>
          </div>
          <?php } ?>
          <?php if ($product['rating']) { ?>
          <div class="rating"><img src="catalog/view/theme/ninghao/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
          <?php } ?>
          <a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="btn btn-large"><?php echo $button_cart; ?></a></div>
        <?php } ?>
      </div>
    </div>
    <?php } ?>
  </div>
  <?php if ($tags) { ?>
  <div class="tags"><b><i class="icon-tags"></i> <?php echo $text_tags; ?></b>
    <?php foreach ($tags as $tag) { ?>
    <a href="<?php echo $tag['href']; ?>"><?php echo $tag['tag']; ?></a>,
    <?php } ?>
  </div>
  <?php } ?>
  <?php echo $content_bottom; ?>
  </div>
 
 
 
 
 </div>
<script type="text/javascript"><!--
$('.colorbox').colorbox({
	overlayClose: true,
	opacity: 0.5
});
//--></script> 
<script type="text/javascript"><!--
$('#button-cart').bind('click', function() {
	$.ajax({
		url: 'index.php?route=checkout/cart/add',
		type: 'post',
		data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, information, .error').remove();
			
			if (json['error']) {
				if (json['error']['option']) {
					for (i in json['error']['option']) {
						$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
					}
				}
			} 
			
			if (json['success']) {
				$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/ninghao/image/close.png" alt="" class="close" /></div>');
					
				$('.success').fadeIn('slow');
					
				$('#cart-total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}	
		}
	});
});
//--></script>
<?php if ($options) { ?>
<script type="text/javascript" src="catalog/view/javascript/jquery/ajaxupload.js"></script>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'file') { ?>
<script type="text/javascript"><!--
new AjaxUpload('#button-option-<?php echo $option['product_option_id']; ?>', {
	action: 'index.php?route=product/product/upload',
	name: 'file',
	autoSubmit: true,
	responseType: 'json',
	onSubmit: function(file, extension) {
		$('#button-option-<?php echo $option['product_option_id']; ?>').after('<img src="catalog/view/theme/ninghao/image/loading.gif" class="loading" style="padding-left: 5px;" />');
	},
	onComplete: function(file, json) {
		$('.error').remove();
		
		if (json.success) {
			alert(json.success);
			
			$('input[name=\'option[<?php echo $option['product_option_id']; ?>]\']').attr('value', json.file);
		}
		
		if (json.error) {
			$('#option-<?php echo $option['product_option_id']; ?>').after('<span class="error">' + json.error + '</span>');
		}
		
		$('.loading').remove();	
	}
});
//--></script>
<?php } ?>
<?php } ?>
<?php } ?>
<script type="text/javascript"><!--
$('#review .pagination a').live('click', function() {
	$('#review').slideUp('slow');
		
	$('#review').load(this.href);
	
	$('#review').slideDown('slow');
	
	return false;
});			

$('#review').load('index.php?route=product/product/review&product_id=<?php echo $product_id; ?>');

$('#button-review').bind('click', function() {
	$.ajax({
		url: 'index.php?route=product/product/write&product_id=<?php echo $product_id; ?>',
		type: 'post',
		dataType: 'json',
		data: 'name=' + encodeURIComponent($('input[name=\'name\']').val()) + '&text=' + encodeURIComponent($('textarea[name=\'text\']').val()) + '&rating=' + encodeURIComponent($('input[name=\'rating\']:checked').val() ? $('input[name=\'rating\']:checked').val() : '') + '&captcha=' + encodeURIComponent($('input[name=\'captcha\']').val()),
		beforeSend: function() {
			$('.success, .warning').remove();
			$('#button-review').attr('disabled', true);
			$('#review-title').after('<div class="attention"><img src="catalog/view/theme/ninghao/image/loading.gif" alt="" /> <?php echo $text_wait; ?></div>');
		},
		complete: function() {
			$('#button-review').attr('disabled', false);
			$('.attention').remove();
		},
		success: function(data) {
			if (data.error) {
				$('#review-title').after('<div class="warning">' + data.error + '</div>');
			}
			
			if (data.success) {
				$('#review-title').after('<div class="success">' + data.success + '</div>');
								
				$('input[name=\'name\']').val('');
				$('textarea[name=\'text\']').val('');
				$('input[name=\'rating\']:checked').attr('checked', '');
				$('input[name=\'captcha\']').val('');
			}
		}
	});
});
//--></script> 
<script type="text/javascript"><!--
$('#tabs a').tabs();
//--></script> 
<script type="text/javascript" src="catalog/view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
if ($.browser.msie && $.browser.version == 6) {
	$('.date, .datetime, .time').bgIframe();
}

$('.date').datepicker({dateFormat: 'yy-mm-dd'});
$('.datetime').datetimepicker({
	dateFormat: 'yy-mm-dd',
	timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script> 
<?php echo $footer; ?>